package com.hzmg.route.akka.handler;

import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.AbstractBehavior;
import akka.actor.typed.javadsl.ActorContext;
import akka.actor.typed.javadsl.Behaviors;
import akka.actor.typed.javadsl.Receive;
import akka.japi.function.Function;
import com.hzmg.route.akka.msg.MsgDemo;
import com.hzmg.support.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HttpActorHandler extends AbstractBehavior<Command> {
    private final Logger logger = LoggerFactory.getLogger(HttpActorHandler.class);

    public HttpActorHandler(ActorContext<Command> context) {
        super(context);
    }

    public static Behavior<Command> create() {
        return Behaviors.setup(context -> new HttpActorHandler(context));
    }

    @Override
    public Receive<Command> createReceive() {
        Behavior<Command> behavior = this;
        return newReceiveBuilder()
                .onMessage(MsgDemo.class, new Function<MsgDemo, Behavior<Command>>() {
                    @Override
                    public Behavior<Command> apply(MsgDemo param) throws Exception {
                        logger.info("httpActor behavior!");
                        param.onMsg("this is actor gateway demo!");
                        return behavior;
                    }
                })
                .build();
    }
}
